<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 86185
  Date: 2021/5/10
  Time: 10:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    //获取项目的根路径
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
    <title>Title</title>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="<%=basePath%>layui-v2.6.5/layui/css/layui.css" media="all">

    <link rel="stylesheet" href="<%=basePath%>swee/sweetalert.css">
    <script src="<%=basePath%>swee/sweetalert-dev.js"></script>
    <script src="<%=basePath%>jquery/jquery-1.12.4.js"></script>
</head>
<body>
<%--<%--%>
<%--    response.sendRedirect("http://localhost:8080/com/UserServlet?select=select");--%>
<%--%>--%>
<form action="<%=basePath%>UserServlet" method="post" style="margin-left: 40%">
    <input type="text" name="name" lay-verify="email" autocomplete="off" class="name">
    <button type="submit" id="select" class="layui-btn layui-btn-radius">查询</button>
</form>

<table class="layui-table" lay-skin="line">
    <colgroup>
        <col width="150">
        <col width="150">
        <col width="200">
        <col>
    </colgroup>
    <thead>
    <tr>
        <th>缴费编号</th>
        <th>诊断号</th>
        <th>用户姓名</th>
        <th>缴费时间</th>
        <th>缴费类型</th>
        <th>缴费状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${requestScope.userPage.list}" var="list">
        <tr class="tr">
            <td>${list.id}</td>
            <td>${list.userId}</td>
            <td>${list.name}</td>
            <td>${list.userTime}</td>
            <td>${list.type}</td>
            <c:if test="${requestScope.stateCount==0}">
                <td>未缴费</td>
            </c:if>
            <td>
                <button type="button" class="layui-btn  layui-btn-radius" id="cost">确认缴费</button>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div>
    <c:if test="${requestScope.userPage.currPageNo>1}">
        <a href="<%=basePath%>UserServlet" ?currPageNo=${requestScope.userPage.currPageNo-1}>上一页</a>
    </c:if>
    ${requestScope.userPage.currPageNo}/${requestScope.userPage.totalCount}
    <c:if test="${requestScope.userPage.currPageNo<requestScope.userPage.totalCount}">
        <a href="<%=basePath%>UserServlet?currPageNo=${requestScope.userPage.currPageNo+1}">下一页</a>
    </c:if>
</div>
<div style="display: none" class="names"><%=request.getAttribute("name")
%>
</div>
<script type="text/javascript">
    $(function () {
        $(".name").val()
        var name = $(".name").val($(".names").text())
        $(".tr #cost").on("click", function () {

            $.ajax({
                url: "http://localhost:8080/com/UserServlet",
                data: {
                    paymentInsert: "Insert",
                    paymentId: $(this).parent().parent().children("td:eq(1)").text()
                },
                type: "POST",
                dataType: "json",
                success: function (data) {
                    if (data == "false") {
                        swal({
                            title: "余额不足！",
                            showCancelButton: false,
                            showConfirmButton: false,
                            showCancelButton: true,
                            confirmButtonColor: "#DD6B55",
                            confirmButtonText: "确定！",
                            cancelButtonText: "取消！",
                            closeOnConfirm: false,
                            closeOnCancel: false
                        })
                    } else {

                        swal({
                                title: "确定缴费吗？",
                                text: "你将无法撤回此次操作！",
                                type: "warning",
                                showCancelButton: true,
                                confirmButtonColor: "#DD6B55",
                                confirmButtonText: "确定！",
                                cancelButtonText: "取消！",
                                closeOnConfirm: false,
                                closeOnCancel: false
                            },
                            function (isConfirm) {
                                if (isConfirm) {
                                    swal({
                                        title: "缴费成功",
                                        text: "本次缴费300元"
                                    }, function () {
                                        window.location.replace("http://localhost:8080/com/UserServlet?name=${name}")
                                    })
                                    <%--setInterval(function () {--%>
                                    <%--    window.location.replace("http://localhost:8080/com/UserServlet?name=${name}")--%>
                                    <%--}, 3000);--%>
                                } else {
                                    swal("取消！", "",
                                        "error");
                                }
                            });

                    }
                }

            })
        })
    })

</script>
</body>
</html>
